// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "AnimatorComponent.generated.h"

class UPaperFlipbook;

UENUM(BlueprintType)
enum EAnimDirection
{
	Up, Down, Left, Right
};

UENUM(BlueprintType)
enum EAnimState
{
	Idle, Walk, Attack
};

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TF_20240717_API UAnimatorComponent : public UActorComponent
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* Default;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Idle", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* IdleDown;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Idle", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* IdleLeft;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Idle", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* IdleRight;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Idle", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* IdleUp;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Attack", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* AttackDown;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Attack", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* AttackLeft;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Attack", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* AttackRight;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Attack", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* AttackUp;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Walk", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* WalkDown;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Walk", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* WalkLeft;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Walk", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* WalkRight;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Anim|Walk", meta=(AllowPrivateAccess=true))
	UPaperFlipbook* WalkUp;

	EAnimDirection CurrentAnimDirection;
	EAnimState CurrentAnimState;

	UPROPERTY(VisibleAnywhere)
	class UPaperFlipbookComponent* Sprite;
public:	
	UAnimatorComponent();

protected:
	virtual void BeginPlay() override;

public:	
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	
	void SetDirection(FVector2D Direction);

	void LookAt(FVector LookPoint);

private:
	EAnimDirection DetermineDirection(const FVector& Position);
	int DetermineQuadrant(const FVector2D& Point);
	
};
